<template>
  <div>
    <sec-desc
      :data="baseInfoData"
      :labelStyle="{ width: '130px', 'text-align': 'right', 'line-height': '30px' }"
      :contentStyle="{ 'line-height': '30px' }"
      :column="3"
      :border="false"
      :colon="true"
      :titleData="titleData"
      title="基础信息"
    >
      <template v-slot:leader="{ data }">
        <sec-account-edit
          :isEdit="$attrs.isEdit"
          prop="leader"
          :user="data.data.leader"
          @editComplete="editComplete"
        ></sec-account-edit>
      </template>
      <template v-slot:businessLineBp="{ data }">
        <sec-account-edit
          :isEdit="$attrs.isEdit"
          prop="businessLineBp"
          :user="data.data.businessLineBp"
          @editComplete="editComplete"
        ></sec-account-edit>
      </template>
      <template v-slot:noticeUsersAccount="{ data }">
        <sec-account-edit
          prop="noticeUsersAccount"
          multiple
          :isEdit="$attrs.isEdit"
          :user="data.data.noticeUsersAccount"
          @editComplete="editComplete"
        ></sec-account-edit>
      </template>
    </sec-desc>
  </div>
</template>

<script>
import { upmAssetUpdateApi } from "api/authApi";
export default {
  name: "secAuthBaseInfo",
  props: {
    data: Object,
  },
  components: {},
  data() {
    return {
      baseInfoData: {},
    };
  },
  created() {
    this.titleData = [
      { label: "系统名称", prop: "name" },
      { label: "系统appid", prop: "appid" },
      { label: "系统回调地址", prop: "homePage" },
      { label: "系统涉及字段", prop: "dataTypeIds" },
      { label: "系统管理员", prop: "appAdmins" },
      { label: "系统归属业务线", prop: "belongBusinessName" },
      { label: "系统归属部门", prop: "deptDescr01" },
      { type: "slot", label: "系统权属负责人", prop: "leader" },
      { type: "slot", label: "业务线BP", prop: "businessLineBp" },
      { type: "slot", label: "关注人", prop: "noticeUsersAccount" }, //支持编辑，支持配置多个人员
      { label: "系统来源", prop: "source" },
      {
        label: "系统是否使用SSO登录",
        prop: "appUseSso",
        formatter: (data) => {
          return this.utils.getDicLabel("whetherNum", data.appUseUpmAuth);
        },
      },
      { label: "系统级别", prop: "appLevelName" },
      {
        label: "系统是否鉴权",
        prop: "appUseUpmAuth",
        formatter: (data) => {
          return this.utils.getDicLabel("appUseUpmAuth", data.appUseUpmAuth);
        },
      },
      {
        label: "系统状态",
        prop: "upmStatus",
        formatter: (data) => {
          return this.utils.getDicLabel("upmStatus", data.upmStatus);
        },
      },
    ];
  },
  mounted() {},
  methods: {
    //params item:{prop:"",user:""}
    editComplete(item) {
      console.log(item);
      this.baseInfoData[item.prop] = item.user;
      let { leader, businessLineBp, noticeUsersAccount } = this.baseInfoData;
      upmAssetUpdateApi({
        id: this.$route.query.id,
        leader,
        businessLineBp,
        noticeUsers: noticeUsersAccount && noticeUsersAccount.length > 0 ? noticeUsersAccount.join(",") : "",
      }).then((res) => {
        this.message.state(res);
      });
    },
  },
  watch: {
    data: {
      deep: true,
      immediate: true,
      handler(newVal) {
        this.baseInfoData = newVal;
      },
    },
  },
};
</script>
<style scoped lang="scss"></style>
